<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="box">点击获取数据</button>
    <script>
    //向别人发送请求并接收数据
    let box= document.querySelector(".box")
    box.onclick=function(){
        let xml=new XMLHttpRequest()
       //0代表被创建但没被调用
        xml.open('get','https://jsonplaceholder.typicode.com/posts')
        //console.log(xml)
        console.log(xml.readyState)//1代表被调用
        xml.send()
        console.log(xml.readyState)
        xml.onreadystatechange = function(){
            //onreadystatechange当状态发生改变时触发
            if(xml.readyState===4){
                console.log(xml.responseText)
                console.log(xml.readyState)
            }
                                        
        }
    }
    </script>
</body>
</html>
